from test_start import test_ssh_setup, test_start
from test_ssh_msg import ssh_msg
from test_redfish_msg import test_redfish_msg, test_redfish_msg_by_doget
# from test_ipmi_msg import test_ipmi_msg
from test_web_msg import test_web_msg
import utils
import time
import requests

if __name__ == "__main__":
    hostname = "127.0.0.1"
    port = 10022
    http_port = 10443
    username = "Administrator"
    password = "Admin@90000"
    cpu_cores = 4
    memory_size = "32GB"
    report = {}
    
    header = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection": "keep-alive",
        "Cookie": "userdata: NULL; SessionId=b2f25f12a95e53ca25ab05185a892fb5ea3ab759fa88591de3ae781cba6e7eaa",
        "From": "WebUI",
        "Host": "127.0.0.1:10443",
        "Sec-CH-UA": '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
        "Sec-CH-UA-Mobile": "?0",
        "Sec-CH-UA-Platform": "Windows",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
    }
    
    
    # 启动时间
    # start_time = time.time()
    # TIMEOUT = 1200
    # CHECK_INTERVAL = 2
    
    # while (time.time() - start_time) < TIMEOUT:
    #     try:
    #         response = requests.get("https://" + hostname + ":10443/UI/Rest/Login", timeout=5, verify=False)
    #         if response.status_code == 200:
    #             service_time = time.time() - start_time
    #             print(f"web启动时间:{service_time}")
    #             break
    #     except requests.exceptions.RequestException:
    #         pass # 忽略连接错误
    #     time.sleep(CHECK_INTERVAL)
        
        
    
    # 下边这些都是要稳定期测试的内容啊
    
    # 测试ssh连接时间，就算不需要这个测试项，也需要在这里建立ssh
    ssh, endtime = test_ssh_setup.try_connect_ssh(hostname, port, username, password)
    report["ssh_connect"] = endtime
    
    
    # 测试命令响应时间
    print("start test cli")
    report = ssh_msg.start_test_msg(ssh, report)
    # print("start test redfish")
    # report = test_redfish_msg.test_redfish(hostname, port, username, password, report)
    # report = test_redfish_msg.test_redfish_inpress(hostname, port, username, password, report) # 这个是压力测试吗，不要一起测吧
    # report = test_redfish_msg_by_doget.test_redfish_doget(hostname, http_port, username, password, report)
    # report = test_redfish_msg_by_doget.test_UI_doget(hostname, http_port, username, password, report, header) 
    # 测试web响应时间
    print("start test web")
    test_web_msg.test_web_msg(hostname, port, username, password, report)
    
    # utils.save_report(hostname, report, cpu_cores, memory_size)
    
    for command, response_time in report.items():
        print(f"命令：{command}，响应时间：{str(response_time)}")